package business.dto;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.ResourceBundle;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class FormElementDTO implements BasicDTO {
	private Integer id=0;

	private String name="";
	
	private ArrayList<String> subLabels=new ArrayList<String>();
	
	private ArrayList<String> subValues=new ArrayList<String>();
	
	
	private ResourceBundle rb = null;
	private ArrayList<String> hp = new ArrayList<String>();

	private static Logger logger = LogManager.getLogger(FormElementDTO.class);
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ArrayList<String> getSubLabels() {
		return subLabels;
	}

	public void setSubLabels(String subLabels) {
		
		String temp[]=subLabels.split("\\|");
		
		this.subLabels = new ArrayList<String>(Arrays.asList(temp));
	}

	public ArrayList<String> getSubValues() {
		return subValues;
	}

	public void setSubValues(String subValues) {
		this.subValues = new ArrayList<String>(Arrays.asList(subValues.split("\\|")));
	}
	
	@Override
	public void setResourceBundle(ResourceBundle rb) {
		this.rb=rb;
		
	}

	@Override
	public void setHeaderParameters(ArrayList<String> hp) {
		this.hp=hp;
		
	}

	@Override
	public ResourceBundle getResourceBundle() {
		return this.rb;
	}

	@Override
	public ArrayList<String> getHeaderParameters() {
		return this.hp;
	}

	@Override
	public String getCustomFields() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setCustomFields(String customFields) {
		// TODO Auto-generated method stub
		
	}
	
	
	public String toString(String selectedValues) {
		StringBuffer sb = new StringBuffer();
		
		ArrayList<String> selectedValuesArray= new ArrayList<String>();
		if(selectedValues!=null){
			selectedValuesArray= new ArrayList<String>(Arrays.asList(selectedValues.split("\\|-\\|")));
		}
		
//		sb.append(head);
		
		for (int i = 0; i < subLabels.size(); i++) {
			
			if(selectedValuesArray.contains(subValues.get(i))){
				sb.	append("<"+subValues.get(i)+" selected='true' >");
			}
			else{
				sb.	append("<"+subValues.get(i)+">");
			}
				sb.	append(subLabels.get(i)).
					append("</"+subValues.get(i)+">");
				;
		}
		
//		sb.append(tail);
		
		logger.debug(sb.toString());
		
		return sb.toString();
	}
}
